package com.cdream.basic.thread;

import lombok.extern.slf4j.Slf4j;

/**
 * jps
 * jstack
 * jconsole
 * @author cdream
 * @date 2022/2/12
 */
@Slf4j(topic = "dead_lock")
public class DeadLockExample {

    public static void main(String[] args) {
        Object lock1 = new Object();
        Object lock2 = new Object();
        new Thread(()->{
            synchronized (lock1){
                log.debug("获取到锁1");
                synchronized (lock2){
                    log.debug("获取到锁2");
                }
            }
        },"t1").start();
        new Thread(()->{
            synchronized (lock2){
                log.debug("获取到锁2");
                synchronized (lock1){
                    log.debug("获取到锁1");
                }
            }
        },"t2").start();
    }
}
